package com.yjd.bi.statistic.control;

import com.yjd.bi.comm.utils.BiDateUtil;
import com.yjd.bi.first.service.IAppPayFirstService;
import com.yjd.bi.first.service.IInvestFirstService;
import com.yjd.comm.annotation.DateString;
import com.yjd.comm.annotation.ServiceRemoteProxy;
import com.yjd.comm.base.control.BaseControl;
import com.yjd.comm.rpm.RpmServiceKeyEnum;
import com.yjd.comm.util.DateUtil;
import com.yjd.comm.util.FrameUtil;
import com.yjd.comm.util.NumberUtil;
import com.yjd.comm.util.ServletUtil;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by yjd-wap on 2017/4/7.
 */

@Controller
@Scope("prototype")
@RequestMapping("/userUse/")
public class UserUseControl extends BaseControl {

    @ServiceRemoteProxy(serviceUrlResouceKey = RpmServiceKeyEnum.RPM_BI_SERVICE_KEY)
    private IInvestFirstService investFirstService;
    @ServiceRemoteProxy(serviceUrlResouceKey = RpmServiceKeyEnum.RPM_BI_SERVICE_KEY)
    private IAppPayFirstService appPayFirstService;

    /**
     * 用户信息统计页面
     *
     * @return
     * @throws Exception String
     */
    @RequestMapping("index")
    public String index() throws Exception {
        request.setAttribute("start", "2013-12-21");
        request.setAttribute("end", BiDateUtil.initBiDate());
        return "userUse.index";
    }

    /**
     * 总览
     *
     * @throws Exception void
     */
    @RequestMapping("summary")
    public void summary(@DateString String start, @DateString String end)
            throws Exception {
        Map<String, Object> paramMap = ServletUtil.getParameterMap(request);
        paramMap.put("startTime", FrameUtil.getTime(DateUtil.parseDate(start,
                DateUtil.PATTERN_yyyyMMdd)));
        paramMap.put("endTime", FrameUtil.getTime(DateUtil.parseDate(end,
                DateUtil.PATTERN_yyyyMMdd)) + 86399);
        Map<String, Object> resultMap = new HashMap<String, Object>();
        // 首充转化时长
        resultMap.put("firstPayUseTimes",
                NumberUtil.formatNumber(appPayFirstService.getFirstPayUseTimes(paramMap),NumberUtil.FORMAT_4));
        // 首投转化时长
        resultMap.put("firstInvestUseTimes",
                NumberUtil.formatNumber(investFirstService.getFirstInvestUseTimes(paramMap),NumberUtil.FORMAT_4));

        super.successData(resultMap);
    }

}
